﻿<%@ Page Language="C#" MasterPageFile="~/Addmin/BackEnd/MTP_Admin.Master" AutoEventWireup="true"
    CodeBehind="MG_Orders.aspx.cs" Inherits="Bussiness.View.BackEnd.MG_Orders" %>

<%@ Register Src="~/Addmin/BackEnd/User_Control/TK_SanPham.ascx" TagName="TKSP" TagPrefix="uc2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <ext:Panel ID="Panel2" runat="server" Title="Quản Hóa Đơn" PaddingSummary="10px 5px 5px 5px">
        <Items>
            <ext:FieldSet ID="FieldSet1" runat="server" Layout="ColumnLayout" Title="Thông tin tìm kiếm"
                PaddingSummary="10px 5px 0 5px" Height="120">
                <Items>
                    <ext:Container ID="Container2" runat="server" LabelAlign="Right" Layout="FormLayout"
                        ColumnWidth=".5">
                        <Items>
                            <ext:TextField ID="tk_soHD" runat="server" FieldLabel="Số hóa đơn" AnchorHorizontal="100%"
                                LabelAlign="Right" IDMode="Static" />
                        </Items>
                        <Items>
                            <ext:TextField ID="tk_tenKH" runat="server" FieldLabel="Tên hàng hóa" AnchorHorizontal="100%"
                                LabelAlign="Right" IDMode="Static" />
                        </Items>
                    </ext:Container>
                    <ext:Container ID="Container3" runat="server" LabelAlign="Right" Layout="FormLayout"
                        ColumnWidth=".5">
                        <Items>
                            <ext:DateField runat="server" ID="tk_NgayBan" IDMode="Static" FieldLabel="Ngày bán"
                                AnchorHorizontal="100%" />
                        </Items>
                        <Items>
                            <ext:TextField ID="tk_soDT" runat="server" FieldLabel="Số điện thoại" AnchorHorizontal="100%"
                                LabelAlign="Right" IDMode="Static" />
                        </Items>
                        <Items>
                            <ext:Button ID="Button3" runat="server" Text="Tìm kiếm" FieldLabel=" " LabelSeparator=" "
                                Icon="Find">
                                <DirectEvents>
                                    <Click OnEvent="Search">
                                    </Click>
                                </DirectEvents>
                            </ext:Button>
                        </Items>
                    </ext:Container>
                </Items>
            </ext:FieldSet>
        </Items>
        <Items>
            <ext:GridPanel ID="DSHoaDon_Grid" IDMode="Static" runat="server" Height="300" AutoScroll="true"
                Region="Center">
                <Store>
                    <ext:Store ID="DSHoaDon_Store" runat="server" AutoDataBind="true" SkipIdForNewRecords="false">
                        <Reader>
                            <ext:JsonReader IDProperty="ID">
                                <Fields>
                                    <ext:RecordField Name="ID" Type="String" Mapping="ID" />
                                    <ext:RecordField Name="NameCus" Type="String" Mapping="NameCus" />
                                    <ext:RecordField Name="PhoneCus" Type="String" Mapping="PhoneCus" />
                                    <ext:RecordField Name="CountProduct" Type="Int" Mapping="CountProduct" />
                                    <ext:RecordField Name="TotalPrice" Type="Int" Mapping="TotalPrice" />
                                    <ext:RecordField Name="Date" Type="Date" Mapping="Date" />
                                </Fields>
                            </ext:JsonReader>
                        </Reader>
                    </ext:Store>
                </Store>
                <ColumnModel ID="ColumnModel2" runat="server" AutoDataBind="true">
                    <Columns>
                        <ext:RowNumbererColumn />
                        <ext:Column ColumnID="ID" Header="Mã" DataIndex="ID" Hidden="true" />
                        <ext:Column Header="Khách hàng" DataIndex="NameCus" AutoDataBind="true" Width="200"
                            MenuDisabled="True" />
                        <ext:Column Header="Số điện thoại" DataIndex="PhoneCus" AutoDataBind="true" Width="150" />
                        <ext:NumberColumn Header="Số lượng SP" DataIndex="CountProduct" AutoDataBind="true"
                            Width="90" MenuDisabled="True" />
                        <ext:NumberColumn Header="Tổng tiền" DataIndex="TotalPrice" AutoDataBind="true" MenuDisabled="True"
                            Format="0,00" />
                        <ext:DateColumn Header="Ngày bán" DataIndex="Date" AutoDataBind="true" MenuDisabled="True"
                            Format="dd/MM/yyyy" />
                        <ext:CommandColumn Header="Action">
                            <Commands>
                                <ext:GridCommand Icon="Delete" CommandName="Delete" ToolTip-Text="Xóa">
                                </ext:GridCommand>
                                <ext:CommandSeparator />
                                <ext:GridCommand Icon="NoteEdit" CommandName="Edit" ToolTip-Text="Sửa/Xem" />
                            </Commands>
                        </ext:CommandColumn>
                    </Columns>
                </ColumnModel>
                <BottomBar>
                    <ext:PagingToolbar ID="PagingToolBar1" runat="server" PageSize="20" StoreID="DSHoaDon_Store"
                        DisplayInfo="false" />
                </BottomBar>
                <SelectionModel>
                    <ext:RowSelectionModel runat="server" ID="RowSelectionModel1">
                    </ext:RowSelectionModel>
                </SelectionModel>
                <Listeners>
                    <Command Handler="detail(command, record.data.ID)" />
                </Listeners>
            </ext:GridPanel>
        </Items>
        <Buttons>
            <ext:Button runat="server" Text="Thêm" ID="them" Icon="Add">
                <Listeners>
                    <Click Fn="showDetail" />
                </Listeners>
            </ext:Button>
            
        </Buttons>
    </ext:Panel>

    <script type="text/javascript">
    var showResult = function(btn) {
    };
    function detail(command, id) {
        if (command == 'Delete') {
            Ext.MessageBox.confirm('Chú ý', 'Bạn có muốn xóa Hóa đơn này không?',
        function(btn) {
            if (btn == 'yes') {
                window.location = 'MG_Orders.aspx?Action=' + command + '&ID=' + id;
            }
            else {
                return false;
            }

        });

    } else window.location = 'Order_Detail.aspx?Action=' + command + '&ID=' + id;
    }



    function AddProperty() {
        var grid = Ext.getCmp('pu_sizeSL_Grid');
        grid.getRowEditor().stopEditing();
        var numOfRow = grid.getStore().getCount();
        grid.insertRecord(numOfRow);
        grid.getView().refresh();
        grid.getView().focusRow(numOfRow);

        grid.getSelectionModel().selectRow(numOfRow);

        grid.getRowEditor().startEditing(numOfRow);
    }




    //tu dong xoa dung khi du lieu tren Grid Null
    var DeleteRow = function() {
        var store = Ext.getCmp('pu_sizeSL_Grid').getStore();
        var index = 0;
        store.each(function(record) {
            if (record.data['Size'] == "" || record.data['Amount'] == "") {

                store.removeAt(index);
            }
            index = index + 1;
        }
)
    };



    function showDetail() {
        //Ext.getCmp('mg_HoaDon').setVisible(true);
        window.location = '/View/BackEnd/Order_Detail.aspx';
    }
    function closeDetail() {
       // Ext.getCmp('mg_HoaDon').setVisible(false);
    }


    
    
    </script>

</asp:Content>
